import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import { AtButton, } from 'taro-ui'
import { DNavBar } from '@/components'
import http from '@/api'
import './index.scss'

export default class EntManageDetail extends Component {
    state = {
        inreviewIcon: require('../../../assets/images/icon／审核中@2x.png'),
        verifiedIcon: require('../../../assets/images/icon／已认证@2x.png'),
        refusedIcon: require('../../../assets/images/icon／被拒绝@2x.png'),
        reomveIcon: require('../../../assets/images/icon／被移除@2x.png'),
        entInfo: '',
        entLicenseUrl: '', // 营业执照
        idCardFront: '',
        idCardReverse: '',
        shopImg: '', // 门店照片
    }

    componentDidShow() {
        this.getEntInfo()
    }

    async getEntInfo() {
        let entInfo = await http.getEntinfo()
        if (entInfo.fileList.length) {
            entInfo.fileList.forEach(item => {
                switch (item.cfType) {
                    case '1': // 营业执照
                        this.setState({
                            entLicenseUrl: item.cfFileUrl
                        })
                        break;
                    case '2': // 法人身份证正面
                        this.setState({
                            idCardFront: item.cfFileUrl
                        })
                        break;
                    case '3': // 法人身份证反面
                        this.setState({
                            idCardReverse: item.cfFileUrl
                        })
                        break;
                    case '4': // 门店照片
                        this.setState({
                            shopImg: item.cfFileUrl
                        })
                        break;
                    default:
                        break;
                }
            })
        }
        this.setState({
            entInfo
        })
    }

    filterApplyStatus() {
        let { entInfo, inreviewIcon, verifiedIcon, refusedIcon, reomveIcon } = this.state
        switch (entInfo.eaIsAppro) {
            case '0': // 待审核
                return {
                    text: '待审核',
                    icon: inreviewIcon
                }
            case '1': // 审核通过
                return {
                    text: '已认证',
                    icon: verifiedIcon
                }
            case '2': // 被拒绝
                return {
                    text: '被拒绝',
                    icon: refusedIcon
                }
            case '3': // 被移除
                return {
                    text: '被移除',
                    icon: reomveIcon
                }
            default:
                break;
        }
    }

    render() {
        const { entInfo, entLicenseUrl, idCardFront, idCardReverse, shopImg } = this.state

        return (
            <View className="entmanage_detail">
                <DNavBar title="企业认证详情"></DNavBar>
                <View className="container">
                    <View className="entinfo">
                        <View className="info_item">
                            <Text className="info_item_label">企业名称</Text>
                            <Text className="info_item_value">{entInfo.entName}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">社会信用代码</Text>
                            <Text className="info_item_value">{entInfo.entCreditCode}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">法人姓名</Text>
                            <Text className="info_item_value">{entInfo.entOwner}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">所在区域</Text>
                            <Text className="info_item_value">{entInfo.entDis}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">企业地址</Text>
                            <Text className="info_item_value">{entInfo.entAddr}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">企业性质</Text>
                            <Text className="info_item_value">{entInfo.entAtt}</Text>
                        </View>

                        <View className="img_item">
                            <View className="info_item">
                                <Text className="info_item_label">企业营业执照</Text>
                                <Text className="info_item_value"></Text>
                            </View>
                            <Image className="img" src={entLicenseUrl}></Image>
                        </View>
                        <View className="img_item">
                            <View className="info_item">
                                <Text className="info_item_label">企业门店照片</Text>
                                <Text className="info_item_value"></Text>
                            </View>
                            <Image className="img" src={shopImg}></Image>
                        </View>
                        <View className="img_item">
                            <View className="info_item">
                                <Text className="info_item_label">法人身份证</Text>
                                <Text className="info_item_value"></Text>
                            </View>
                            <Image className="img" src={idCardFront}></Image>
                            <Image className="img" src={idCardReverse}></Image>
                        </View>
                        <Image className="apply_status_img" src={entInfo && this.filterApplyStatus.bind(this)().icon}></Image>
                    </View>

                    <View className="border"></View>

                    <View className="apply_info">
                        <View className="info_item">
                            <Text className="info_item_label">提交认证时间</Text>
                            <Text className="info_item_value">{entInfo.createTime}</Text>
                        </View>
                        <View className="info_item">
                            <Text className="info_item_label">审核状态</Text>
                            <Text className="info_item_value">{entInfo && this.filterApplyStatus.bind(this)().text}</Text>
                        </View>
                        {
                            entInfo.eaIsAppro != 0 && < View className="info_item">
                                <Text className="info_item_label">审核时间</Text>
                                <Text className="info_item_value">{entInfo.approTime}</Text>
                            </View>
                        }
                        {
                            entInfo.eaIsAppro == 2 && <View className="info_item">
                                <Text className="info_item_label">审核原因</Text>
                                <Text className="info_item_value">{decodeURI(entInfo.approDesc)}</Text>
                            </View>
                        }
                        {
                            (entInfo.eaIsAppro == 2 || entInfo.eaIsAppro == 3) && <AtButton className="btn" onClick={() => {
                                Taro.navigateTo({
                                    url: '/pages/enterpriseform/enterpriseform?rep=true'
                                })
                            }}>重新认证</AtButton>
                        }
                    </View>
                </View>
            </View>
        )
    }
}
